<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../include/admincontent.jsp" %>
<style>
    .inputform tbody .radio1 span {
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .inputform tbody .radio1 span input[type=checkbox] {
        display: none;
    }
</style>
<div id="Content">
    <form id="modelform" method="post" action="/SysAdmin/EditUser">
        <input type="hidden" name="id" value="${user.id}" datatype="*" nullmsg="非法访问"/>
<%--        <div class="btnbar">
            <button type="submit" class="save">保 存</button>
        </div>--%>
        <div class="toolbars">
            <a id="save">
                <em class="ico16 save_traft_16"></em>
                <span class="menu_span" title="保存">保存</span>
            </a>
        </div>
        <table class="treeTable inputform" style="margin-top: 10px">
            <tbody>
            <tr>
                <td width="80">员 工 号：</td>
                <td>${user.ucode}</td>
            </tr>
            <tr>
                <td>员工姓名：</td>
                <td>${user.uname}</td>
            </tr>
            <tr>
                <td>联系电话：</td>
                <td><input type="text" name="utel" value="${user.utel}" datatype="*" nullmsg="联系电话不能为空！"/></td>
            </tr>
            <tr>
                <td>所属部门：</td>
                <td><input type="hidden" value="${user.udept}" name="deptcode" id="deptcode"/><input type="text"
                                                                                                     value="${user.udeptname}"
                                                                                                     name="deptname"
                                                                                                     id="deptname"
                                                                                                     class="select"
                                                                                                     onFocus="blur()"
                                                                                                     datatype="*"
                                                                                                     nullmsg="所属部门不能为空！"/>
                </td>
            </tr>
            <tr>
                <td>用户角色：</td>
                <td>
                    <div class="radio1">
                        <c:forEach var="role" items="${roles}">
                            <span>${role.rname}<input type="checkbox" name="rid" value="${role.id}"/></span>
                        </c:forEach>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
    <div id="uroles">${uroles}</div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#save").click(function () {
            var data = {};
            data["id"] = $("input[name='id']").val();
            data["utel"] = $("input[name='utel']").val();
            data["deptcode"] = $("input[name='deptcode']").val();
            data["deptname"] = $("input[name='deptname']").val();
            data["rid"] = $("input[name='rid']").val();
            $.ajax({
                url: "/SysAdmin/EditUser",
                type: 'POST',
                data: data,
                success: function (data) {
                    layer.msg(data.Message, {icon: 1, time: 2000});
                    setTimeout(()=>{
                        parent.location.reload();
                    }, 2000);

                },
                error: function (data) {
                    layer.msg(data.Message, {icon: 2, time: 2000});
                }
            });
        });

        $('.inputform .select').click(function () {
            openLayer('选择部门', '/SysAdmin/getdepts', '100%', '100%');
        });

        //初始化角色列表
        $('#uroles input').each(function () {
            var id = $(this).val();
            $('.radio1 span').each(function () {
                if ($(this).find('input[type=checkbox]').val() == id) {
                    $(this).addClass('checked');
                    $(this).find('input[type=checkbox]').prop('checked', true);
                }
            });
        });

        //选择角色
        $(document).delegate('.inputform tbody div.radio1 span', 'click', function () {
            if ($(this).hasClass('checked')) {
                $(this).removeClass('checked');
                $(this).find('input[type=checkbox]').prop('checked', false);
            } else {
                $(this).addClass('checked');
                $(this).find('input[type=checkbox]').prop('checked', true);
            }
        });
    });
</script>
</body>
</html>